package com.linghu.controller;

import com.alibaba.dashscope.app.ApplicationResult;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;

import com.linghu.Service.QueryApiService;
import com.linghu.entity.Ans;
import com.linghu.entity.cont.Constrant;
import com.linghu.utils.AnswerDoing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.util.Scanner;

/**
 * @author linghu
 * @date 2023/11/1 21:50
 * 服务端程序，负责向大模型发送http请求，接受resp响应
 */
@RestController
@RequestMapping(value = "/lingHuApi")
@CrossOrigin
public class QueryBack {
    @Resource
    private QueryApiService queryApiService;

    @PostMapping("/mode")
    @ResponseBody
    public String sendHttp(@RequestBody Ans ans) throws NoApiKeyException, InputRequiredException {

        String usage = queryApiService.usage(ans);
        //输出答案
        System.out.println("ans="+usage);
        return usage;
    }

    @PostMapping("/que")
    @ResponseBody
    public String sendQues(@RequestBody Ans ans) throws NoApiKeyException, InputRequiredException {

        ApplicationResult usage = queryApiService.ragCall(ans);
        //输出答案
        System.out.println("ans="+usage.getOutput().getText());
        return usage.getOutput().getText();
    }
}
